/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.pa036is.dtoconverters;

import cz.muni.fi.pa036is.dto.MatchBasicTO;
import cz.muni.fi.pa036is.dto.MatchDetailTO;
import cz.muni.fi.pa036is.dto.MatchFormTO;
import cz.muni.fi.pa036is.dto.MatchGridTO;
import cz.muni.fi.pa036is.entity.Match;
import cz.muni.fi.pa036is.entity.Person;
import cz.muni.fi.pa036is.entity.Season;
import java.sql.Date;

/**
 *
 * @author Shebik
 */
public class MatchConverter {

    private MatchConverter() {
    }

    public static Match convertToMatch(final MatchFormTO matchFormTO) {
        final Match match = new Match();
        match.setId(matchFormTO.getId());
								
        match.setSeasonId(matchFormTO.getSeasonId());
        match.setPlayer1Id(matchFormTO.getPlayer1Id());
        match.setPlayer2Id(matchFormTO.getPlayer2Id());
        match.setDateAndTime(matchFormTO.getDateAndTime());
        return match;
    }
				
				public static MatchBasicTO convertToMatchBasicTO(final MatchDetailTO matchDetailTO) {
        final MatchBasicTO match = new MatchBasicTO();
        match.setId(matchDetailTO.getId());
								match.setPlayer1Id(matchDetailTO.getPlayer1Id());
								match.setPlayer2Id(matchDetailTO.getPlayer2Id());
								match.setDateAndTime(matchDetailTO.getDateAndTime());
								
        return match;
    }
				
    public static MatchFormTO convertToMatchFormTO(final Match match) {
        final MatchFormTO matchFormTO = new MatchFormTO();
        matchFormTO.setId(match.getId());
        matchFormTO.setPlayer1Id(match.getPlayer1Id());
        matchFormTO.setPlayer2Id(match.getPlayer2Id());
        matchFormTO.setDateAndTime(match.getDateAndTime());
								matchFormTO.setSeasonId(match.getSeasonId());
        return matchFormTO;
    }

    public static MatchDetailTO convertToMatchDetailTO(final Match match) {
        final MatchDetailTO matchDetailTO = new MatchDetailTO();
        matchDetailTO.setId(match.getId());
        matchDetailTO.setPlayer1Id(match.getPlayer1Id());
        matchDetailTO.setPlayer2Id(match.getPlayer2Id());
        matchDetailTO.setDateAndTime(match.getDateAndTime());
        return matchDetailTO;
    }
				
    public static MatchBasicTO convertToMatchBasicTO(final Match match) {
        final MatchBasicTO matchBasicTO = new MatchBasicTO();
        matchBasicTO.setId(match.getId());
        matchBasicTO.setPlayer1Id(match.getPlayer1Id());
        matchBasicTO.setPlayer2Id(match.getPlayer2Id());
        matchBasicTO.setDateAndTime(match.getDateAndTime());
        return matchBasicTO;
    }

    public static MatchGridTO convertToMatchGridTO(final Match match,
            final Season season, final Person player1, final Person player2,
            final String finalScore) {
        final MatchGridTO matchGridTO = new MatchGridTO();
        matchGridTO.setId(match.getId());
        matchGridTO.setPlayer1FirstName(player1.getFirstName());
        matchGridTO.setPlayer1LastName(player1.getLastName());
        matchGridTO.setPlayer2FirstName(player2.getFirstName());
        matchGridTO.setPlayer2LastName(player2.getLastName());
        matchGridTO.setSeasonName(season.getName());
        matchGridTO.setSeasonStartDate(season.getStartDate());
        matchGridTO.setSeasonEndDate(season.getEndDate());
        matchGridTO.setFinalScore(finalScore);
		if (match != null && match.getDateAndTime() != null) {
			matchGridTO.setDateAndTime(new Date(match.getDateAndTime().getTime()));
		}
        return matchGridTO;
    }

}
